home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_qt3.idb / usr / freeware / Qt / examples / demo / qasteroids / sprites.h.z / sprites.h
Encoding:
C/C++ Source or Header  |  2002-04-08  |  2.6 KB  |  130 lines

  1. /*
  2.  * KAsteroids - Copyright (c) Martin R. Jones 1997
  3.  *
  4.  * Part of the KDE project
  5.  */
  6.  
  7. #ifndef __SPRITES_H__
  8. #define __SPRITES_H__
  9.  
  10. #include <qcanvas.h>
  11.  
  12. #define ID_ROCK_LARGE           1024
  13. #define ID_ROCK_MEDIUM          1025
  14. #define ID_ROCK_SMALL           1026
  15.  
  16. #define ID_MISSILE              1030
  17.  
  18. #define ID_BIT                  1040
  19. #define ID_EXHAUST              1041
  20.  
  21. #define ID_ENERGY_POWERUP       1310
  22. #define ID_TELEPORT_POWERUP     1311
  23. #define ID_BRAKE_POWERUP        1312
  24. #define ID_SHIELD_POWERUP       1313
  25. #define ID_SHOOT_POWERUP        1314
  26.  
  27. #define ID_SHIP                 1350
  28. #define ID_SHIELD               1351
  29.  
  30. #define MAX_SHIELD_AGE          350
  31. #define MAX_POWERUP_AGE         500
  32. #define MAX_MISSILE_AGE         40
  33.  
  34. class KMissile : public QCanvasSprite
  35. {
  36. public:
  37.     KMissile( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c )
  38.         { myAge = 0; }
  39.  
  40.     virtual int rtti() const { return ID_MISSILE; }
  41.  
  42.     void growOlder() { myAge++; }
  43.     bool expired() { return myAge > MAX_MISSILE_AGE; }
  44.  
  45. private:
  46.     int myAge;
  47. };
  48.  
  49. class KBit : public QCanvasSprite
  50. {
  51. public:
  52.     KBit( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c )
  53.     {  death = 7; }
  54.  
  55.     virtual int rtti() const {  return ID_BIT; }
  56.  
  57.     void setDeath( int d ) { death = d; }
  58.     void growOlder() { death--; }
  59.     bool expired() { return death <= 0; }
  60.  
  61. private:
  62.     int death;
  63. };
  64.  
  65. class KExhaust : public QCanvasSprite
  66. {
  67. public:
  68.     KExhaust( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c )
  69.     {  death = 1; }
  70.  
  71.     virtual int rtti() const {  return ID_EXHAUST; }
  72.  
  73.     void setDeath( int d ) { death = d; }
  74.     void growOlder() { death--; }
  75.     bool expired() { return death <= 0; }
  76.  
  77. private:
  78.     int death;
  79. };
  80.  
  81. class KPowerup : public QCanvasSprite
  82. {
  83. public:
  84.   KPowerup( QCanvasPixmapArray *s, QCanvas *c, int t ) : QCanvasSprite( s, c ),
  85.         myAge( 0 ), type(t) { }
  86.  
  87.   virtual int rtti() const { return type; }
  88.  
  89.   void growOlder() { myAge++; }
  90.   bool expired() const { return myAge > MAX_POWERUP_AGE; }
  91.  
  92. protected:
  93.   int myAge;
  94.   int type;
  95. };
  96.  
  97. class KRock : public QCanvasSprite
  98. {
  99. public:
  100.     KRock (QCanvasPixmapArray *s, QCanvas *c, int t, int sk, int st) : QCanvasSprite( s, c )
  101.         { type = t; skip = cskip = sk; step = st; }
  102.  
  103.     void nextFrame()
  104.     {
  105.         if (cskip-- <= 0) {
  106.         setFrame( (frame()+step+frameCount())%frameCount() );
  107.         cskip = QABS(skip);
  108.         }
  109.     }
  110.  
  111.     virtual int rtti() const { return type; }
  112.  
  113. private:
  114.     int type;
  115.     int skip;
  116.     int cskip;
  117.     int step;
  118. };
  119.  
  120. class KShield : public QCanvasSprite
  121. {
  122. public:
  123.   KShield( QCanvasPixmapArray *s, QCanvas *c )
  124.       : QCanvasSprite( s, c ) {}
  125.  
  126.   virtual int rtti() const { return ID_SHIELD; }
  127. };
  128.  
  129. #endif
  130.